      SUBROUTINE PK_ORTHOGRAPHIC(KFILDO,IPACK,ND5,IS3,NS3,IPKOPT,
     1                           L3264B,LOCN,IPOS,IER,*)
C
C        MARCH   2000   LAWRENCE   GSC/TDL   ORIGINAL CODING
C        JANUARY 2001   GLAHN      COMMENTS; IER = 303 CHANGED TO 304;
C                                  ADDED CHECK FOR SIZE OF IS3( )
C        JANUARY 2001   GLAHN/LAWRENCE CHANGED IS3(65) TO ABS(IS3(65))
C                                  IN CALL TO BKBG
C
C        PURPOSE
C            PACKS TEMPLATE 3.90, A SPACE VIEW PERSPECTIVE
C            (ORTHOGRAPHIC) MAP PROJECTION TEMPLATE IN SECTION 3.
C            IT IS THE RESPONSIBILITY OF THE CALLING ROUTINE TO
C            PACK THE FIRST 13 OCTETS IN SECTION 3.
C
C        DATA SET USE
C           KFILDO - UNIT NUMBER FOR OUTPUT (PRINT) FILE. (OUTPUT)
C
C        VARIABLES
C              KFILDO = UNIT NUMBER FOR OUTPUT (PRINT) FILE. (INPUT)
C            IPACK(J) = THE ARRAY THAT HOLDS THE ACTUAL PACKED MESSAGE
C                       (J=1,ND5). (INPUT/OUTPUT)
C                 ND5 = THE SIZE OF THE ARRAY IPACK( ). (INPUT)
C              IS3(J) = CONTAINS THE MERCATOR PROJECTION
C                       INFORMATION (IN ELEMENTS 15 THROUGH 77)
C                       THAT WILL BE PACKED INTO IPACK( ) (J=1,NS3).
C                       (INPUT/OUTPUT)
C                 NS3 = SIZE OF IS3( ). (INPUT) 
C              IPKOPT = PACKING INDICATOR:
C                       0 = ERROR, DON'T PACK
C                       1 = PACK IA( ), SIMPLE
C                       2 = PACK IA( ) AND IB( ), SIMPLE
C                       3 = PACK COMPLEX OR SPATIAL DIFFERENCING
C                       4 = PACK COMPLEX.
C                       (INPUT)
C              L3264B = THE INTEGER WORD LENGTH IN BITS OF THE MACHINE
C                       BEING USED. VALUES OF 32 AND 64 ARE
C                       ACCOMMODATED. (INPUT)
C                LOCN = THE WORD POSITION TO PLACE THE NEXT VALUE.
C                       (INPUT/OUTPUT)
C                IPOS = THE BIT POSITION IN LOCN TO START PLACING
C                       THE NEXT VALUE. (INPUT/OUTPUT)
C                 IER = RETURN STATUS CODE. (OUTPUT)
C                         0 = GOOD RETURN.
C                       1-4 = ERROR CODES GENERATED BY PKBG. SEE THE 
C                             DOCUMENTATION IN THE PKBG ROUTINE.
C                       302 = IS3( ) HAS NOT BEEN DIMENSIONED LARGE
C                             ENOUGH TO CONTAIN THE ENTIRE TEMPLATE. 
C                       304 = IS3(13) DOES NOT INDICATE POLAR
C                             STEREOGRAPHIC MAP PROJECTION; 
C                             INCORRECTLY CALLED SUBROUTINE. 
C                       310 = UNRECOGNIZED OR UNSUPPORTED SHAPE OF
C                             EARTH CODE IN IS3(15) RETURNED BY
C                             SUBROUTINE EARTH.
C                   * = ALTERNATE RETURN WHEN IER .NE. 0
C
C             LOCAL VARIABLES
C               ISIGN = A FLAG INDICATING WHETHER A VALUE TO BE
C                       PACKED IS POSITIVE OR NEGATIVE.
C                   N = L3264B = THE INTEGER WORD LENGTH IN BITS OF
C                       THE MACHINE BEING USED. VALUES OF 32 AND
C                       64 ARE ACCOMMODATED.
C             MINSIZE = THE SMALLEST ALLOWABLE DIMENSION FOR IS3( ).
C
C        NON SYSTEM SUBROUTINES CALLED
C           EARTH, PKBG
C
      PARAMETER(MINSIZE=77)
C
      DIMENSION IPACK(ND5),IS3(NS3)
C
      N=L3264B
      IER=0
C
C        CHECK TO MAKE SURE THAT THE USER WANTS TO PROCESS
C        A SPACE VIEW PERSPECTIVE PROJECTION.  CHECK FOR NS3 GE 13
C        ASSURES A VALUE FOR IS3(13).
C
      IF(NS3.GE.13)THEN
C
         IF (IS3(13).NE.90)THEN
D           WRITE(KFILDO,10)IS3(13)
D10         FORMAT(/' MAP PROJECTION CODE ',I4,' INDICATED BY IS3(13)'/
D    1              ' IS NOT SPACE VIEW PERSPECTIVE. PLEASE REFER TO'/
D    2              ' THE GRIB2 DOCUMENTATION TO DETERMINE THE'/
D    3              ' CORRECT MAP PROJECTION PACKER TO CALL.'/) 
            IER=304
            GO TO 900
         ENDIF
C
      ELSE
         IER=302
         GO TO 900
      ENDIF
C
C        CHECK THE DIMENSIONS OF IS3( ).
C
      IF(NS3.LT.MINSIZE)THEN
         IER=302
         GO TO 900
      ENDIF
C
C        PACK THE SHAPE OF THE EARTH.
      CALL EARTH(KFILDO,IPACK,ND5,IS3,NS3,N,LOCN,IPOS,IER)
      IF(IER.NE.0)GOTO 900
C
C        PACK THE NUMBER POINTS ALONG THE X-AXIS AND THE NUMBER
C        OF POINTS ALONG THE Y-AXIS (Nx & Ny).
      CALL PKBG(KFILDO,IPACK,ND5,LOCN,IPOS,IS3(31),32,N,IER,*900)
      CALL PKBG(KFILDO,IPACK,ND5,LOCN,IPOS,IS3(35),32,N,IER,*900)
C
C        PACK THE LATITUDE & LONGITUDE OF THE SUB-SATELLITE POINT 
C        TAKING INTO CONSIDERATION THAT THE VALUE MAY BE
C        NEGATIVE.
      ISIGN=0
      IF(IS3(39).LT.0) ISIGN=1
      CALL PKBG(KFILDO,IPACK,ND5,LOCN,IPOS,ISIGN,1,N,IER,*900)
      CALL PKBG(KFILDO,IPACK,ND5,LOCN,IPOS,ABS(IS3(39)),
     1          31,N,IER,*900)
      ISIGN=0
      IF(IS3(43).LT.0) ISIGN=1
      CALL PKBG(KFILDO,IPACK,ND5,LOCN,IPOS,ISIGN,1,N,IER,*900)
      CALL PKBG(KFILDO,IPACK,ND5,LOCN,IPOS,ABS(IS3(43)),
     1          31,N,IER,*900)
C
C        PACK THE RESOLUTION AND COMPONENT FLAGS.
      CALL PKBG(KFILDO,IPACK,ND5,LOCN,IPOS,IS3(47),8,N,IER,*900)
C
C        PACK THE APPARENT DIAMETER OF THE EARTH IN GRID LENGTHS,
C        IN THE X-DIRECTION AND THE Y-DIRECTION.
      CALL PKBG(KFILDO,IPACK,ND5,LOCN,IPOS,IS3(48),32,N,IER,*900)
      CALL PKBG(KFILDO,IPACK,ND5,LOCN,IPOS,IS3(52),32,N,IER,*900)
C
C        PACK THE X-COORDINATE OF THE SUB-SATELLITE POINT. 
      CALL PKBG(KFILDO,IPACK,ND5,LOCN,IPOS,IS3(56),32,N,IER,*900)
C
C        PACK THE Y-COORDINATE OF THE SUB-SATELLITE POINT. 
      CALL PKBG(KFILDO,IPACK,ND5,LOCN,IPOS,IS3(60),32,N,IER,*900)
C
C        PACK THE SCANNING MODE. CHECK TO SEE IF THE DATA POINTS 
C        HAVE BEEN ORDERED BOUSTROPHEDONICALLY. IF SO, SET BIT 4
C        TO 1 IN THE SCANNING MODE OCTET.
C
CWDT  IF((IPKOPT.EQ.3).OR.(IPKOPT.EQ.4))THEN
CWDT     IS3(64)=IOR(IS3(64),16)
CWDT  ELSE
         IS3(64)=IAND(IS3(64),239)
CWDT  ENDIF
C
      CALL PKBG(KFILDO,IPACK,ND5,LOCN,IPOS,IS3(64),8,N,IER,*900)
C
C        PACK THE ORIENTATION ANGLE OF THE GRID (THE ANGLE
C        BETWEEN THE MAP'S I DIRECTION AND THE EARTH'S
C        EQUATOR). ALLOW FOR THIS VALUE TO BE NEGATIVE.
      ISIGN=0
      IF(IS3(65).LT.0) ISIGN=1
      CALL PKBG(KFILDO,IPACK,ND5,LOCN,IPOS,ISIGN,1,N,IER,*900)
      CALL PKBG(KFILDO,IPACK,ND5,LOCN,IPOS,ABS(IS3(65)),31,N,IER,*900)
C
C
C        PACK THE ALTITUDE OF THE CAMERA FROM THE EARTH'S CENTER
C        MEASURED IN UNITS OF THE EARTH'S EQUATORIAL RADIUS.
      CALL PKBG(KFILDO,IPACK,ND5,LOCN,IPOS,IS3(69),32,N,IER,*900)
C
C        PACK THE X-COORDINATE OF THE SECTOR IMAGE (Xo)
C        AND THE Y-COORDINATE OF THE SECTOR IMAGE (Yo).
      CALL PKBG(KFILDO,IPACK,ND5,LOCN,IPOS,IS3(73),32,N,IER,*900)
      CALL PKBG(KFILDO,IPACK,ND5,LOCN,IPOS,IS3(77),32,N,IER,*900)
C
C       ERROR RETURN SECTION
 900  IF(IER.NE.0)RETURN 1 
C
      RETURN
      END
